package com.shuoyue.ycgk.ui.course;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.shuoyue.ycgk.Constant;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.appcatch.SPUtils;
import com.shuoyue.ycgk.base.BaseMvpActivity;
import com.shuoyue.ycgk.entity.UserInfo;
import com.shuoyue.ycgk.ui.common.CstWebActivity;
import com.shuoyue.ycgk.ui.course.contract.SpecialContract;
import com.shuoyue.ycgk.utils.GlideUtil;
import com.shuoyue.ycgk.utils.XToast;
import com.shuoyue.ycgk.views.RegistSpecialCourseDialog;
import com.shuoyue.ycgk.views.ResizableImageView;

import butterknife.BindView;
import butterknife.OnClick;

public class SpecialCourseActivity extends BaseMvpActivity<SpecialContract.Presenter>
        implements SpecialContract.View {
    RegistSpecialCourseDialog registSpecialCourseDialog;
    @BindView(R.id.page_title)
    TextView pageTitle;
    @BindView(R.id.img)
    ResizableImageView img;


    /**
     * 初始化layouy
     */
    @Override
    protected int getLayoutId() {
        return R.layout.activity_special_course;
    }

    /**
     * 初始化布局
     */
    @Override
    protected void initView() {
        pageTitle.setText("神秘课程预约");
    }

    @Override
    public void initData() {
        super.initData();
        mPresenter = new SpecialContract.Presenter();
        mPresenter.attachView(this);
        GlideUtil.loadImage(mContext, "https://new-intrain-attachment.oss-cn-huhehaote.aliyuncs.com/images/advert/20210331/20210331113017.jpg",
                img);
    }

    @OnClick({R.id.back, R.id.service, R.id.regist})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.service:
//
//                Uri uri = Uri.parse("https://yzf.qq.com/xv/web/static/chat/index.html?sign=37ef9b97d7710ac47743cbe719e1b8634b8c182e07fc93010143f7c17a4f0030531c516d443b651fca36c1a2c761b970ab03f178"); //设置要操作的路径
//
//                Intent it = new Intent();
//
//                it.setAction(Intent.ACTION_VIEW); //设置要操作的Action
//
//                it.setData(uri); //要设置的数据
//
//                startActivity(it); //执行跳转
//                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constant.serviceUrl)));

//                CstWebActivity.start(mContext, Constant.serviceUrl, "咨询");
                if(Constant.isOpenServiceExploer){
                    Uri uri = Uri.parse(Constant.serviceUrl);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                }else {
                    CstWebActivity.start(mContext, Constant.serviceUrl, "咨询");

                }

                break;
            case R.id.regist:
                if (registSpecialCourseDialog == null) {
                    registSpecialCourseDialog = new RegistSpecialCourseDialog(mContext,
                            (name, phone, timeStr,type) -> {
//
                                mPresenter.registSpecialCourse(name, phone, timeStr,type);
                            });
                }
                registSpecialCourseDialog.show();
                break;
        }
    }

    @Override
    public void registSuc(String phone) {
        XToast.toast(mContext, "报名成功");
        UserInfo userInfo = SPUtils.getUserInfo(mContext);
        if (userInfo != null && userInfo.getPhone().equals(phone)) {
            userInfo.setPhone(phone);
        }
        SPUtils.updateUserInfo(mContext, userInfo);
        finish();
    }

}
